import {type MockMethod, Recordable} from "vite-plugin-mock";
import {
    authUserLoginUrl,
    realmLoadUserPageUrl,
    realmUserGroupLevelPageUrl,
    realmUserGroupOfPlatformListUrl,
    realmQueryPageUrl,
    realmUserSaveUrl,
    realmSaveUrl,
    realRemoveUserGroupFromUserUrl,
    realmRemoveUserFromUserGroupUrl, realmRemoveUserGroupFromPlatformUrl, realmAddUserToUserGroupUrl
} from "../src/apis/url";

const PREFIX: string = 'mock';

const mock: Array<MockMethod> = [
    {
        url: authUserLoginUrl('/mock'),
        method: 'post',
        response: () => {
            return {
                code: 0,
                message: "操作成功",
                data: {
                    user: {
                        userId: '88888888888888',
                        name: 'licode',
                        headUrl: 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg',
                    },
                    cred: {
                        accessToken: '6666666666',
                        refreshToken: '999999999',
                    }
                }
            }
        }
    },
    {
        url: realmUserGroupOfPlatformListUrl('/mock'),
        method: 'post',
        response: () => {
            return {
                code: 0,
                message: "操作成功",
                data: {
                    total: 2,
                    data: [
                        {
                            id: '1',
                            name: '人事部',
                        },
                        {
                            id: '2',
                            name: '技术部',
                        }
                    ]
                }
            }
        }
    },
    {
        url: realmLoadUserPageUrl('/mock'),
        method: 'post',
        response: () => {
            return {
                code: 0,
                message: "操作成功",
                data: {
                    total: 2,
                    data: [
                        {
                            id: '1',
                            name: 'licode',
                        },
                        {
                            id: '2',
                            name: 'wangrong',
                        }
                    ]
                }
            }
        }
    },
    {
        url: realmAddUserToUserGroupUrl('/mock'),
        method: 'post',
        response: () => {
            return {
                code: 0,
                message: "操作成功",
            }
        }
    },
    {
        url: realmUserGroupLevelPageUrl('/mock'),
        method: 'post',
        response: (opt: {
            url: Recordable;
            body: Recordable;
            query: Recordable;
            headers: Recordable;
        }) => {
            let data: any;
            if (!opt.body.parentId) {
                data = [{
                    id: '1',
                    parentId: undefined,
                    name: '技术部',
                    applyDate: '2016-10-10',
                },
                    {
                        id: '2',
                        parentId: undefined,
                        name: '采购部',
                        applyDate: '2016-10-10',
                        state: 0,
                    },
                    {
                        id: '3',
                        parentId: undefined,
                        name: '市场部',
                        applyDate: '2016-10-10',
                        state: 0,
                    },
                    {
                        id: '4',
                        parentId: undefined,
                        name: '人事部',
                        applyDate: '2016-10-10',
                        state: 0,
                    }
                ]
            } else {
                if ("1" === opt.body.parentId) {
                    data = [{
                        id: '1-1',
                        parentId: '1',
                        name: 'JAVA开发',
                        applyDate: '2016-10-10',
                    },
                        {
                            id: '1-2',
                            parentId: '1',
                            name: '手机APP',
                            applyDate: '2016-10-10',
                        },
                        {
                            id: '1-3',
                            parentId: '1',
                            name: 'WEB前端',
                            applyDate: '2016-10-10',
                        },
                        {
                            id: '1-4',
                            parentId: '1',
                            name: '嵌入式开发',
                            applyDate: '2016-10-10',
                        },
                    ]
                } else if ("2" === opt.body.parentId) {
                    data = [{
                        id: '2-1',
                        parentId: '2',
                        name: '数码一部',
                        applyDate: '2016-10-10',
                    },
                        {
                            id: '2-2',
                            parentId: '2',
                            name: '家电',
                            applyDate: '2016-10-10',
                        },
                        {
                            id: '2-3',
                            parentId: '2',
                            name: '办公用品',
                            applyDate: '2016-10-10',
                        },
                    ]
                }
                if ("1-1" === opt.body.parentId) {
                    data = [{
                        id: '1-1-1',
                        parentId: '1-1',
                        name: 'JAVA测试',
                        applyDate: '2016-10-10',
                    },
                        {
                            id: '1-1-2',
                            parentId: '1-1',
                            name: 'JAVA架构师',
                            applyDate: '2016-10-10',
                        },
                    ]
                }
            }

            return {
                code: 0,
                message: "操作成功",
                data: {
                    data: data
                }
            }
        }
    },
    {
        url: realmRemoveUserGroupFromPlatformUrl('/mock'),
        method: 'post',
        response: () => {
            return {
                code: 0,
                message: "操作成功",
            }
        }
    },
    {
        url: realRemoveUserGroupFromUserUrl('/mock'),
        method: 'post',
        response: () => {
            return {
                code: 0,
                message: "操作成功",
            }
        }
    },
    {
        url: realmRemoveUserFromUserGroupUrl('/mock'),
        method: 'post',
        response: () => {
            return {
                code: 0,
                message: "操作成功",
            }
        }
    },
    {
        url: realmQueryPageUrl('/mock'),
        method: 'post',
        response: () => {
            return {
                code: 0,
                message: "操作成功",
                data: {
                    total: 1,
                    data: [
                        {
                            id: '2',
                            orgName: 'XX科技',
                            name: '支付平台',
                            state: 0,
                            createDate: '2016-10-16 08:05',
                            contact: '李小曼'
                        },
                    ]
                }
            }
        }
    },
    {
        url: `/${PREFIX}/api/realm/user/page`,
        method: 'post',
        response: (opt: {
            url: Recordable;
            body: Recordable;
            query: Recordable;
            headers: Recordable;
        }) => {
            return {
                code: 0,
                message: "操作成功",
                data: {
                    total: 2,
                    data: [
                        {
                            id: '1',
                            name: '生产一部',
                            phone: '13800013800',
                            state: 0,
                            createTime: '2016-10-16'
                        },
                        {
                            id: '2',
                            name: '生产二部',
                            phone: '13800013800',
                            state: 1,
                            createTime: '2016-10-16'
                        }
                    ]
                }
            }
        }
    },
    {
        url: `/${PREFIX}/api/realm/setting/delete`,
        method: 'post',
        response: () => {
            return {
                code: -1,
                message: "删除领域设置失败!"
            }
        }
    },
    {
        url: `/${PREFIX}/api/realm/user/group/load`,
        method: 'post',
        response: () => {
            return {
                code: 0,
                message: "操作成功",
                data: {
                    total: 2,
                    data: [
                        {
                            id: '1',
                            name: '研发中心',
                            code: 'dev-center',
                            comment: '研发中心',
                            createTime: '2016-10-16',
                            children: [
                                {
                                    id: '1-1',
                                    parentId: '1',
                                    name: '开发部',
                                    code: 'dev',
                                    comment: '123',
                                    createTime: '2016-10-16',
                                },
                                {
                                    id: '1-2',
                                    parentId: '1',
                                    name: '测试部',
                                    code: 'test',
                                    comment: '123',
                                    createTime: '2016-10-16',
                                },
                                {
                                    id: '1-3',
                                    parentId: '1',
                                    name: '产品部',
                                    code: 'product',
                                    comment: '123',
                                    createTime: '2016-10-16',
                                    children: [
                                        {
                                            id: '2-1',
                                            parentId: '1-3',
                                            name: '市场',
                                            code: 'market',
                                            comment: 'market',
                                            createTime: '2016-10-16',
                                        },
                                        {
                                            id: '2-2',
                                            parentId: '1-3',
                                            name: '销售',
                                            code: 'sale',
                                            comment: 'sale',
                                            createTime: '2016-10-16',
                                        },
                                    ]
                                }
                            ]
                        }
                    ]
                }
            }
        }
    },
    {
        url: realmSaveUrl('/mock'),
        method: 'post',
        response: () => {
            return {
                code: 0,
                message: "操作成功"
            }
        }
    },
    {
        url: `/${PREFIX}/api/realm/setting/save`,
        method: 'post',
        response: () => {
            return {
                code: 0,
                message: "操作成功"
            }
        }
    },
    {
        url: `/${PREFIX}/api/realm/setting/load`,
        method: 'post',
        response: () => {
            return {
                code: 0,
                message: "操作成功",
                data: {
                    total: 1,
                    data: [
                        {
                            id: '1',
                            name: '主题颜色',
                            code: 'theme-color',
                            value: '#FFFFFF',
                            comment: '用户设置对应的主题颜色',
                            createTime: '2016-10-16'
                        }
                    ]
                }
            }
        }
    },
    {
        url: realmUserSaveUrl('/mock'),
        method: 'post',
        response: () => {
            return {
                code: 0,
                message: "操作成功"
            }
        }
    },
    {
        url: `/${PREFIX}/api/realm/user/group/save`,
        method: 'post',
        response: () => {
            return {
                code: 0,
                message: "操作成功"
            }
        }
    },
    {
        url: `/${PREFIX}/api/user/group/delete`,
        method: 'post',
        response: () => {
            return {
                code: -1,
                message: "删除用户分组失败!"
            }
        }
    },
]

export default mock;
